package com.CMS.client.ui.view;

import com.CMS.client.CMSConstants;
import com.CMS.client.CMSMessage;
import com.google.gwt.core.client.GWT;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.VLayout;
import com.smartgwt.client.widgets.toolbar.ToolStrip;
import com.smartgwt.client.widgets.toolbar.ToolStripButton;

public abstract class BaseABMView extends VLayout{

	protected ToolStrip toolBar = new ToolStrip();
	protected ToolStripButton btnNuevo;
	protected ToolStripButton btnAceptar;
	protected ToolStripButton btnCancelar;
	protected ToolStripButton btnBorrar;
	protected ToolStripButton btnActualizar;
	protected CMSConstants constants = GWT.create(CMSConstants.class);
	protected CMSMessage messages = GWT.create(CMSMessage.class); 
	
	public BaseABMView() {
		super();
		
		crearToolBar();	
	}
	
	private void crearToolBar(){
		toolBar.setWidth("100%");
		toolBar.setHeight(19);
		
		btnNuevo = new ToolStripButton();
		btnAceptar = new ToolStripButton();
		btnActualizar = new ToolStripButton();
		btnBorrar = new ToolStripButton();
		btnCancelar = new ToolStripButton();
		
		btnNuevo.setIcon("icons/16/buttonNew.png"); 
		btnNuevo.setTitle(constants.captionNewButton());
		btnNuevo.addClickHandler(new ClickHandler() {			
			@Override
			public void onClick(ClickEvent event) {
				setNew();
			}
		});
		toolBar.addButton(btnNuevo);
		//Separador
		toolBar.addSeparator();
		//Boton Aceptar
		btnAceptar.setIcon("icons/16/buttonAcept.png"); 
		btnAceptar.setTitle(constants.captionAcceptButton());
		btnAceptar.addClickHandler(new ClickHandler() {			
			@Override
			public void onClick(ClickEvent event) {
				setAccept();
			}
		});
		toolBar.addButton(btnAceptar);
		//Separador
		toolBar.addSeparator();
		//Boton cancelar
		btnCancelar.setIcon("icons/16/buttonCancel.png"); 
		btnCancelar.setTitle(constants.captionCancelButton());
		btnCancelar.addClickHandler(new ClickHandler() {			
			@Override
			public void onClick(ClickEvent event) {
				setCancel();
			}
		});
		toolBar.addButton(btnCancelar);
		//Separador
		toolBar.addSeparator();
		//Boton Refrescar
		btnActualizar.setIcon("icons/16/buttonRefresh.png"); 
		btnActualizar.setTitle(constants.captionRefreshButton());
		btnActualizar.addClickHandler(new ClickHandler() {			
			@Override
			public void onClick(ClickEvent event) {
				setRefersh();
			}
		});
		toolBar.addButton(btnActualizar);
		//Separador
		toolBar.addSeparator();
		//Boton Borrar
		btnBorrar.setIcon("icons/16/buttonremove.png"); 
		btnBorrar.setTitle(constants.captionDeleteButton());
		btnBorrar.addClickHandler(new ClickHandler() {			
			@Override
			public void onClick(ClickEvent event) {
				setDelete();
			}
		});
		toolBar.addButton(btnBorrar);
		
		this.addMember(toolBar);
	}
	
	public void setAddButtonToolbar(ToolStripButton btn){
		toolBar.addButton(btn);
	}
	
	public void setSeparatorToolBar(){
		toolBar.addSeparator();
	}
	
	public abstract void setNew();
	public abstract void setAccept();
	public abstract void setCancel();
	public abstract void setDelete();
	public abstract void setRefersh();
	
}
